<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/vue_2.5.22.js"></script>
<script src="./lib/vue-router_3.0.2.js"></script>
</head>
<body>

    <div id="app">

        <!-- 第二步 添加路由连接 -->
        <router-link to="/user/1">User1</router-link>
        <router-link to="/user/2">User2</router-link>
        <router-link to="/user/3">User3</router-link>
        <router-link to="/register">Register</router-link>

        <!-- 第三步添加路由填充位置 -->
        <router-view></router-view>
    </div>

<script>
    // 第四步创建路由对象
    const User = {
        props:['id'],
        template:`<div>
            <h1>用户组件:{{id}}</h1>
            </div>
            `
    }
    const Register = {
        template:'<h1>注册组件</h1>'
    }
    const router = new VueRouter({
        routes:[
            {path:'/',redirect:'/user'},
            {path:'/user/:id',component:User,props:true},
            {path:'/register',component:Register},
        ]
    })

    var vm = new Vue({
        el:'#app',
        data:{

        },
        router
    })
</script>
</body>

</html>